package com.vf.cloud.paas.app.master.api.scene.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jfinal.kit.StrKit;
import com.vf.cloud.paas.app.master.common.domain.SceneAction;
import com.vf.cloud.paas.app.master.common.domain.User;
import com.vf.cloud.paas.common.util.R;
import com.vf.cloud.paas.common.util.UuidUtil;
import com.vf.cloud.paas.common.util.WebUtils;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/scene/action")
public class SceneActionController {
	
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public R<SceneAction> save(HttpServletRequest request,@RequestBody SceneAction sceneAction) {
		User user = WebUtils.getCurUser(request);
		if(StrKit.isBlank(sceneAction.getId())) {
			sceneAction.setId(UuidUtil.getUUID());
			sceneAction.setCreateUserId(user.getId());
			if(sceneAction.save()) {
				 return R.ok(sceneAction);
			}
		}
		sceneAction.setModifyUserId(user.getId());
		if (sceneAction.update()) {
			return R.ok(sceneAction);
		}
		return R.failed();
	}

}
